package com.example.hangzhou.welbeing.mytestdemoapp.mvp.activity;

import android.app.ActivityOptions;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.CardView;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.example.hangzhou.welbeing.mytestdemoapp.R;
import com.example.hangzhou.welbeing.mytestdemoapp.mvp.personter.MyLoginPersenter;
import com.example.hangzhou.welbeing.mytestdemoapp.mvp.view.ISMyLoginView;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 杭州惟君医疗科技有限公司13
 * Created by 20433 on 2018/5/4
 *
 * @desc 东风山河绿，春已不折柳，繁花看不尽，处处惹人留
 * @desc 佛祖镇楼，bug辟容易
 */

public class MyLoginActivity extends AppCompatActivity  implements ISMyLoginView {
    @Bind(R.id.et_username)
    EditText etUsername;
    @Bind(R.id.et_password)
    EditText etPassword;
    @Bind(R.id.bt_go)
    Button btGo;
    @Bind(R.id.cv)
    CardView cv;
    @Bind(R.id.fab)
    FloatingActionButton fab;
    private MyLoginPersenter mMyLoginPersenter = new MyLoginPersenter(this);

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_login);
        ButterKnife.bind(this);
    }

    @OnClick({R.id.bt_go, R.id.fab})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.bt_go:
                mMyLoginPersenter.JudgeISLogin(this);
                break;
            case R.id.fab:
                break;
        }
    }

    @Override
    protected void onRestart() {
        super.onRestart();
    }

    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    public void toMainActivityPager() {
        Intent i2 = new Intent(MyLoginActivity.this,MyMainActivity.class);
        startActivity(i2);
        overridePendingTransition(R.anim.slide_right_in, R.anim.slide_left_out);
    }

    @Override
    public void toRegisterActivityPager() {
        getWindow().setExitTransition(null);
        getWindow().setEnterTransition(null);
        ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(MyLoginActivity.this, fab, fab.getTransitionName());
        startActivity(new Intent(MyLoginActivity.this, MyRegisterActivity.class), options.toBundle());
    }

    @Override
    public String getUserName() {
        return etUsername.getText().toString().trim();
    }

    @Override
    public String getPassword() {
        return etPassword.getText().toString().trim();
    }

    @Override
    public void showSnackbar(String info) {
//        Snackbar.make(btGo,info,Snackbar.LENGTH_SHORT).setAction("撤销",new View.OnClickListener(){
//            @Override
//            public void onClick(View view){
//                Toast.makeText(MyLoginActivity.this, "撤销了", Toast.LENGTH_SHORT).show();
//            }
//        }).show();
        Toast.makeText(MyLoginActivity.this, info, Toast.LENGTH_SHORT).show();
    }
    @Override
    public boolean onKeyDown(int keyCode,KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK){

            finish();
            overridePendingTransition(R.anim.slide_left_in, R.anim.slide_right_out);
        }

        return super.onKeyDown(keyCode, event);//继续执行父类其他点击事件
    }
}
